import Cookies from 'js-cookie'

const TokenKey = 'ppk-token'
// const TokenKey = 'vue_admin_template_token'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

// ! localStorage 存储  json未处理
export function localgettoken() {
  return sessionStorage.getItem(TokenKey)
  // return localStorage.getItem(TokenKey)
}
export function localsettoken(token) {
  return sessionStorage.setItem(TokenKey, token)
  // return localStorage.setItem(TokenKey, token)
}
export function localsetuserNo(userNo) {
  return localStorage.setItem('userNo', userNo)
}
export function localgetuserNo() {
  return localStorage.getItem('userNo')
}
export function localremovetoken() {
  return sessionStorage.removeItem(TokenKey)
  // return localStorage.removeItem(TokenKey)
}
export function getUserName() {
  // console.log(JSON.parse(localStorage.getItem(TokenKey)), 'sdafasdf',localStorage.getItem(TokenKey))
  // if (!localStorage.getItem(TokenKey)) return '-'
  // if (!JSON.parse(localStorage.getItem(TokenKey))) return '-'
  // return JSON.parse(localStorage.getItem(TokenKey)).userNo
  if (!sessionStorage.getItem(TokenKey)) return '-'
  if (!JSON.parse(sessionStorage.getItem(TokenKey))) return '-'
  return JSON.parse(sessionStorage.getItem(TokenKey)).userNo
}

export function getUserInfo() {
  if (!sessionStorage.getItem(TokenKey)) return null
  if (!JSON.parse(sessionStorage.getItem(TokenKey))) return null
  return JSON.parse(sessionStorage.getItem(TokenKey))
}

export function getUserExtend() {
  if (!sessionStorage.getItem(TokenKey)) return null
  if (!JSON.parse(sessionStorage.getItem(TokenKey))) return null
  try {
    return JSON.stringify(JSON.parse(sessionStorage.getItem(TokenKey)).exts)
  } catch (error) {
    return ''
  }
}
